package ${package.Controller};

import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ${package.Entity}.${cfg.vo};
import ${package.Entity}.${cfg.bo};
import ${package.Entity}.${cfg.updateBO};
import com.eairlv.cli.utils.request.PageBO;
import com.eairlv.cli.utils.request.PageVO;
import com.eairlv.cli.utils.request.Result;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@Api(description="${cfg.objectName}接口")
@RestController
@RequestMapping("/${table.name}")
public class ${table.controllerName} {

    @Autowired
    ${table.serviceName} ${cfg.objectServiceName};

    @GetMapping("/{id}")
    @ApiOperation("通过ID获取对象")
    public Result<${cfg.vo}> get(@PathVariable @ApiParam(required = true, value = "对象ID") Integer id) {
        return Result.ok(${cfg.objectServiceName}.get(id));
    }

    @PostMapping
    @ApiOperation("新增对象")
    public Result<Object> add(@RequestBody ${cfg.bo} ${cfg.boVariable}){
        Object id = ${cfg.objectServiceName}.add(${cfg.boVariable});
        return Result.ok(id);
    }

    @PutMapping
    @ApiOperation("修改对象")
    public Result update(@RequestBody ${cfg.updateBO} ${cfg.updateBOVariable}){
        ${cfg.objectServiceName}.update(${cfg.updateBOVariable});
        return Result.ok();
    }

    @DeleteMapping(path = "/{id}")
    @ApiOperation("删除对象")
    public Result delete(@PathVariable Long id) {
        ${cfg.objectServiceName}.delete(id);
        return Result.ok();
    }

    @GetMapping
    @ApiOperation("获取分页对象")
    public Result<PageVO<${cfg.vo}>> page(PageBO pageBO){
        PageVO<${cfg.vo}> pageVO = ${cfg.objectServiceName}.pageView(pageBO);
        return Result.ok(pageVO);
    }
}

